<template>
  <div>
    <el-form
      ref="formDataRef"
      :model="formData"
      :rules="formDataRules"
      :label-position="labelPosition"
      label-width="80px"
    >
      <el-row :gutter="10">
        <el-col :span="8"
          ><div class="grid-content bg-purple">
            <el-form-item label="申请人名称">
              <el-input v-model="formData.applicantName"></el-input>
            </el-form-item></div
        ></el-col>
        <el-col :span="8"
          ><div class="grid-content bg-purple">
            <el-form-item label="申请人电话">
              <el-input v-model="formData.applicantTel"></el-input>
            </el-form-item></div
        ></el-col>
        <el-col :span="8"
          ><div class="grid-content bg-purple">
            <el-form-item label="客户名称">
              <el-input v-model="formData.custName"></el-input>
            </el-form-item></div
        ></el-col>
        <el-col :span="8"
          ><div class="grid-content bg-purple">
            <el-form-item label="统一社会信用代码">
              <el-input v-model="formData.sociaCode"></el-input>
            </el-form-item></div
        ></el-col>
        <el-col :span="8"
          ><div class="grid-content bg-purple">
            <el-form-item label="证件类型">
              <el-select v-model="formData.cardType" placeholder="请选择">
                <el-option
                  v-for="item in cardTypeQueryType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item></div
        ></el-col>
        <el-col :span="8"
          ><div class="grid-content bg-purple">
            <el-form-item label="证件号码">
              <el-input v-model="formData.cardNumber"></el-input>
            </el-form-item></div
        ></el-col>
        <el-col :span="24"
          ><div class="grid-content bg-purple">
            <el-form-item label="错误种类">
              <el-checkbox-group v-model="formData.errType" size="small">
                <el-checkbox-button
                  v-for="item in errTypeArr"
                  :label="item"
                  :key="item"
                  >{{ item }}</el-checkbox-button
                >
              </el-checkbox-group>
            </el-form-item>
          </div></el-col
        >
        <el-col :span="24"
          ><div class="grid-content bg-purple">
            <el-form-item label="证件照片">
              <el-upload
                class="avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <img v-if="imageUrl" :src="imageUrl" class="avatar" />
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item></div
        ></el-col>
        <el-col :span="24"
          ><div class="grid-content bg-purple">
            <el-form-item label="问题描述">
              <el-input
                type="textarea"
                v-model="formData.desc"
                rows="5"
              ></el-input>
            </el-form-item></div
        ></el-col>
      </el-row>
    </el-form>
    <div class="demo-drawer__footer">
      <el-button @click="resetForm">取 消</el-button>
      <el-button type="primary" @click="submitForm" :loading="loading">{{
        loading ? "提交中 ..." : "确 定"
      }}</el-button>
    </div>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="imageUrl" alt="" />
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "CustomerZy",
  data() {
    return {
      //证件类型
      cardTypeQueryType: [
        {
          value: "1",
          label: "精确查询",
        },
        {
          value: "2",
          label: "模糊查询",
        },
      ],
      errTypeArr: [
        "统一社会信用代码错误",
        "经营期限字段信息错误",
        "客户名称字段错误",
        "组代无数据",
        "经营状态错误",
        "其他 ",
      ],

      formData: {
        applicantName: "", //申请人名称
        applicantTel: "", //申请人电话
        custName: "", //客户名称
        // 统一社会信用代码
        sociaCode: "",
        //证件类型
        cardType: "1", //

        // 证件号码
        cardNumber: "111",
        // 证件类型选中
        checkboxGroup2: ["上海"],
        // 错误类型
        errType: ["统一社会信用代码错误"], //错误类型
      },
      // 校验规则
      formDataRules: {
        // 申请人名称
        applicantName: [
          { required: true, message: "请输入申请人名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        applicantTel: [
          { required: true, message: "请选择证件类型", trigger: "change" },
        ],
        // 客户名称
        custName: [
          { required: true, message: "请填写客户名称", trigger: "blur" },
        ],
        // 证件类型
        cardType: [
          { required: true, message: "请填写营销责任地", trigger: "blur" },
        ],
        pic: [{ required: true, message: "请上传证件照片", trigger: "change" }],
      },

      // 表单标签排列方式方式
      labelPosition: "left",
      //上传图片路径
      imageUrl: "",
      // 图片弹窗
      dialogVisible: false,
      // 加载中...
      dialog: false,
      // 加载中...
      loading: false,
      //
      desc: "", //textarea 里的内容
    };
  },
  components: {},
  created() {},
  mounted() {
    this.$refs.formDataRef.resetFields();
  },
  methods: {
    //证件类型下拉框
    cardTypeQueryTypeHandel() {},

    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    // 提交表单
    cancelForm() {
      this.loading = false;
      this.dialog = false;
      clearTimeout(this.timer);
    },
    //提交表单
    submitForm() {
      this.$bus.$emit("close");
      this.$store.commit("setDrawStatus");
    },
    // 重置表单
    resetForm() {
      this.$refs.formDataRef.resetFields();
    },
  },
};
</script>
<style lang="scss" scoped>
.demo-drawer__footer {
  position: absolute;
  left: 60px;
  right: 60px;
  bottom: 20px;
  text-align: center;
}
.demo-drawer__footer button {
  display: inline-block;
  width: 45%;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
